<template>
  <div class="home">
    <el-container>
      <el-aside width="auto">
        <div class="logo">
        </div>
        <el-menu 
        class="el-menu-admin" 
        :router="true"
        @open="handleOpen" 
        @close="handleClose" 
        background-color="#545c64" 
        text-color="#fff" 
        active-text-color="#ffd04b" 
        :collapse="isCollapse">
          <el-submenu index="">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/home/users">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item index="2-1">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item index="3-1">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>订单管理</span>
            </template>
            <el-menu-item index="4-1">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>数据统计</span>
            </template>
            <el-menu-item index="5-1">
              <i class="el-icon-menu"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="icon-menu" @click="toggleCollapse"></div>
          <div class="userInfo">
            您好，
            {{$store.getters.username}}
            <el-button type="text" @click="loginOut">退出</el-button>
          </div>
          <div class="title">
            <h2>电商后台管理系统</h2>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { mapGetters} from "vuex";
export default {
  data() {
    return {
      isCollapse: false
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    loginOut() {
      localStorage.removeItem("myToken");
      localStorage.removeItem("username");
      this.$router.push({ name: "Login" });
    }
  }
};
</script>
<style lang="scss" scoped>
.home {
  height: 100%;
  width: 100%;
  // position: fixed;
  background-color: orange;

  > .el-container {
    height: 100%;
    .el-header {
      background-color: #96ec80;
      color: #333;
      > .icon-menu {
        float: left;
        &:before {
          font-size: 40px;
          line-height: 60px;
        }
      }
      > .title {
        color: #fff;
        line-height: 60px;
        text-align: center;
      }
      > .userInfo {
        float: right;
        // width: 40px;
        line-height: 60px;
        text-align: center;
      }
    }
    .el-aside {
      background-color: #545c64;
      color: #333;
      box-sizing: border-box;
      // height: 100%;
      .logo {
        height: 60px;
        background: url("../assets/home.png");
        background-size: cover;
        background-color: white;
      }
      .el-menu{
        border: 0;
      }
    }

    .el-main {
      background-color: #e9eef3;
      color: #333;
    }
  }
}
</style>